package com.cardbaobao.cardbabyclient.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.buried.Self;
import com.cardbaobao.cardbabyclient.model.QrCodeDebitFeeRateData;
import com.cardbaobao.cardbabyclient.model.QuickDebitFeeRateData;
import com.cardbaobao.cardbabyclient.ui.activity.base.BaseActivity;
import com.cardbaobao.cardbabyclient.ui.adapter.QrCodeDebitFeeRateAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.QuickDebitFeeRateAdapter;
import com.cardbaobao.cardbabyclient.buried.GoogleAnalyticsUtil;
import com.cardbaobao.cardbabyclient.widget.TitleBar;
import com.cardbaobao.cardbabyclient.widget.divider.VerticalItemDecoration;
import com.scwang.smartrefresh.layout.util.DensityUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Jiangzx on 2017/9/16 13:49.
 */

public class FeeRateActivity extends BaseActivity {
    public static final String QUICK_DEBIT_FEE_RATE_LIST_ARRAY ="quickFeeRates";
    public static final String QR_CODE_DEBIT_FEE_RATE_LIST_ARRAY ="qrCodeFeeRates";
    public static final String FEE_TYPE_I="feeType";

    public static final int QUICK_DEBIT_FEE_TYPE=1;//快捷收款费率
    public static final int QR_CODE_DEBIT_FEE_TYPE=2;//二维码收款费率

    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    int type;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_fee_rate;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        titleBar.setLeftViewOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        LinearLayoutManager layoutManager=
                new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
        recyclerView.setLayoutManager(layoutManager);
        VerticalItemDecoration decoration=new VerticalItemDecoration(0, DensityUtil.dp2px(15));
        recyclerView.addItemDecoration(decoration);

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        Intent intent=getIntent();

        mCurrentPageId= Self.Page.app_rate_details;

        type=intent.getIntExtra(FEE_TYPE_I,QUICK_DEBIT_FEE_TYPE);
        if(QUICK_DEBIT_FEE_TYPE==type){
            List<QuickDebitFeeRateData.FeeRate> data=
                    intent.getParcelableArrayListExtra(QUICK_DEBIT_FEE_RATE_LIST_ARRAY);
            List<QuickDebitFeeRateAdapter.FeeRateBean> beanList=new ArrayList<>();
            for(int i=0,size=data.size();i<size;i++){
                beanList.add(new QuickDebitFeeRateAdapter.FeeRateBean(
                        QuickDebitFeeRateAdapter.FeeRateBean.TYPE_ITEM,data.get(i)));
            }
            beanList.add(new QuickDebitFeeRateAdapter.FeeRateBean(
                    QuickDebitFeeRateAdapter.FeeRateBean.TYPE_FOOTER,null));
            QuickDebitFeeRateAdapter adapter=new QuickDebitFeeRateAdapter(beanList);
            recyclerView.setAdapter(adapter);
        }else if(QR_CODE_DEBIT_FEE_TYPE==type){
            List<QrCodeDebitFeeRateData.FeeRate> data=
                    intent.getParcelableArrayListExtra(QR_CODE_DEBIT_FEE_RATE_LIST_ARRAY);
            List<QrCodeDebitFeeRateAdapter.FeeRateBean> beanList=new ArrayList<>();
            for(int i=0,size=data.size();i<size;i++){
                beanList.add(new QrCodeDebitFeeRateAdapter.FeeRateBean(
                        QrCodeDebitFeeRateAdapter.FeeRateBean.TYPE_ITEM,data.get(i)));
            }
            beanList.add(new QrCodeDebitFeeRateAdapter.FeeRateBean(
                    QrCodeDebitFeeRateAdapter.FeeRateBean.TYPE_FOOTER,null
            ));
            QrCodeDebitFeeRateAdapter adapter=new QrCodeDebitFeeRateAdapter(beanList);
            recyclerView.setAdapter(adapter);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(QUICK_DEBIT_FEE_TYPE==type){
            GoogleAnalyticsUtil.setScreenName("快捷收款费率");
        }else{
            GoogleAnalyticsUtil.setScreenName("二维码收款费率");
        }
    }
}
